package BinaryTree;
/*
 * 把二叉搜索树转换为累加树
 */
import BinaryTree.init.TreeNode;

public class lc538 {

    int pre = 0;
    public TreeNode convertBST(TreeNode root) {
        convertBST1(root);
        return root;
    }
    public void convertBST1(TreeNode root) {
        if (root == null) return;
        convertBST(root.right);
        pre += root.val;
        root.val = pre;
        convertBST(root.left);
    }

}
